<template>
  <el-container style="height: 100%;" class="dealBaseHome">
    <el-header v-loading="loading" class="app-header">
      <div class="titlebar">
        <div class="titlebar-image">
          <UploadAvatar :logo-info="logoInfo" @appendData="uploadImg($event)" />
        </div>
        <div class="titlebar-title">
          <div class="title">
            <div class="tit">
              <el-tooltip placement="bottom">
                <div slot="content">{{ companyName }}</div>
                <el-button class="tipText" type="text">
                  <p>{{ companyName }}</p>
                </el-button>
              </el-tooltip>
            </div>
            <div v-if="companyName === '国际化'" class="tab-change" style="flex: 1;justify-content: flex-end;">
              <Internationalization />
            </div>
          </div>
        </div>
      </div>
    </el-header>
    <div class="page-component__scroll">
      <fullView
        ref="fullView"
        :bus-id="busId"
        bus-type="fund"
        :child-left-menu="menuList"
        :bus-name="companyName"
        :default-active="activeIndex"
      />
    </div>
  </el-container>
</template>

<script>
import { getCompanyBase, uploadAvatar } from '@/api/company/base/companyBase'
import { childMenuList	} from '@/api/system/menu'
import UploadAvatar from '@/components/Avatar/uploadAvatar'
import fullView from '@/components/fullView'
export default {
components: {
  UploadAvatar, fullView
},
filters: {
  ellipsis(value) {
    if (!value) return ''
    if (value.length > 20) {
      return value.slice(0, 20) + '...'
    }
    return value
  }
},
data() {
    return {
      loading: false,
      busId: this.$route.query.companyId,
      // logo
      logoInfo: '',
      // name
      companyName: this.$route.query.companyName,
      // 公司ID
      companyId: this.$route.query.companyId,
      // 表单参数
      form: {},
      menuList: [],
      activeIndex: '',
      parameter: {},
      // 父级菜单标识
      menuIdent: ''

    }
  },
  created() {
    this.getCompany()
    this.getMenuIdent()
    this.listLoad()
  },
  mounted() {
  },
  methods: {
    // 根据来源，获取菜单标识
    getMenuIdent() {
      const source = this.$route.query.source
      if (source === 'BF_PORTFOLIO') {
        this.menuIdent = 'indirect_project'
      } else if (source === 'DEAL_DEBT') {
        this.menuIdent = 'company_manage_debt'
      } else if (source === 'DEAL_EQUITY') {
        this.menuIdent = 'company_manage_equity'
      } else {
        this.menuIdent = 'company_manage'
      }
    },
    // 初始化数据
    getCompany() {
      if (this.companyId !== null && this.companyId !== undefined) {
        getCompanyBase(this.companyId).then(response => {
          this.companyName = document.title = response.data.companyName
          this.logoInfo = response.data.logoInfo
        })
      }
    },
    listLoad() {
      // 菜单列表
      childMenuList(this.menuIdent).then(response => {
        this.menuList = response.rows
        this.activeIndex = this.menuList[0].children[0].id
      })
    },
    // 上传图片
    uploadImg(data) {
      var formData = new FormData()
      formData.append('avatarfile', data)
      formData.append('id', this.$route.query.companyId)
      uploadAvatar(formData).then(response => {
        if (response.code === 200) {
          this.logoInfo = response.msg
          this.msgSuccess(this.$t('修改成功'))
        } else {
          this.msgError(response.msg)
        }
      })
    }
  }
}
</script>

<style scoped>
.voteMain{
  margin-left: 200px;
}
</style>
